package com.ryan.statistic.task;

import com.ryan.statistic.service.StatisticsDailyService;
import com.ryan.statistic.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class ScheduleTask {

    @Autowired
    private StatisticsDailyService statisticsDailyService;

    //每天凌晨1点执行生成前一天的数据的任务
    @Scheduled(cron = "0 0 1 * * ?")
    public void task1(){
        //获取上一天的时间
        String day = DateUtil.formatDate(DateUtil.addDays(new Date(), -1));
        statisticsDailyService.createRegisterData(day);
    }

}